<?php

namespace App\Models;

use App\Models\Base\ProjectRelated;

class ProjectRelatedModel extends ProjectRelated
{
    /**
     * 获取相关ID
     *
     * @param  int  $parentId
     * @return mixed
     * @author lichunguang 153102250@qq.com
     * @since 2022/4/27 下午3:53
     */
    public function getIdsByParentId(int $parentId)
    {
        return self::where('parent_id', $parentId)->pluck('related_id');
    }

    //删除相关文章
    public function deleteIdsByParentId(int $parentId, array $deleteIds)
    {
        if(empty($deleteIds)){
            return false;
        }
        return self::where('parent_id', $parentId)->whereIn('related_id', $deleteIds)->delete();
    }

    //新增相关文章
    public function insertIdsByParentId(int $parentId, array $insertIds)
    {
        if(empty($insertIds)){
            return false;
        }
        $dataList = [];
        foreach ($insertIds as $v){
            $dataList[] = [
                'parent_id' => $parentId,
                'related_id' => $v
            ];
        }
        return self::batchInsert($dataList);
    }
}